//
//  ConfirmOnlineTicketRequest.m
//  EasyToo
//
//  Created by zhengzhe on 13-8-25.
//
//

#import "ConfirmOnlineTicketRequest.h"

@implementation ConfirmOnlineTicketRequest

- (id)confirmonlineTickets:(id<ServerCommunicationDelegate>)delegate
                   orderId:(NSString*)orderId
                cinemaName:(NSString*)cinemaName
                    prices:(NSString*)prices
                  showtime:(NSString*)showtime
                  showdate:(NSString*)showdate
                foretellId:(NSString*)foretellId
                        rk:(NSString*)rk
                      fees:(NSString*)fees
                     count:(NSString*)count
                  allprice:(int)allprice
{
    self = [super init];
    if (self) {
        self.delegate = delegate;
        
        self.requestName = @"ConfirmOnlineTicketRequest";
        
        [self.headerJsonDict setObject:@"018009" forKey:@"TranCode"];
        
        self.url = PROTOCOL_ORDER_URL;
        
        [self.bodyJsonDict setObject:orderId forKey:@"orderId"];
        [self.bodyJsonDict setObject:[self URLEncodedString:cinemaName] forKey:@"cinemaName"];
        [self.bodyJsonDict setObject:showtime forKey:@"showtime"];
        [self.bodyJsonDict setObject:showdate forKey:@"showdate"];
        [self.bodyJsonDict setObject:foretellId forKey:@"foretellId"];
        [self.bodyJsonDict setObject:rk forKey:@"rk"];
        [self.bodyJsonDict setObject:fees forKey:@"fees"];
        [self.bodyJsonDict setObject:count forKey:@"count"];
        
        //银联支付价格
        [self.headerJsonDict setObject:[NSString stringWithFormat:@"%d", allprice*100] forKey:@"TxAmt"];
        
        [self buildJsonRequest];
    }
    return self;
}

- (NSString*)URLEncodedString:(NSString*)input
{
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                           (CFStringRef)input,
                                                                           NULL,
                                                                           CFSTR("!*'();:@&=+$,/?%#[]"),
                                                                           kCFStringEncodingUTF8);
    [result autorelease];
    return result;
}

@end
